﻿function goBack() {
    location.href = "/Province/ProvinceList";
}
function SubData() {
    var postData = {
        ProvinceID: $('#hidProvinceId').val(),
        CreateTime: $("#hidCreateTime").val(),
        ProvinceName: $("#ProvinceName").val().trim(),
        CreateUserID: $('#hidCreateUserID').val(),
        IsActive:$("#PIsActive").val(),
        Remark: HtmlUtil.htmlEncodeByRegExp(CKEDITOR.instances.desTextarea.getData())
    };
    //使用异步进行修改数据的信息
    $.post("/Province/UpdateInfo", postData, function (date) {
        if (date == "suc") {
            //关闭层，刷新表单
            goBack();
        }
        else if (date == "repeat") {
            $.alert({
                title: '系统提示',
                content: '重复数据无法保存！',
                confirm: function () {
                }
            });
        }
        else if (date == "nouser") {
            location.href = '/Login/Index';
        }
        else {
            $.alert({
                title: '系统提示',
                content: '操作失败',
                confirm: function () {
                }
            });
        }
    });
}
$(document).ready(function () {
    $("#rightResources").addClass("active");
    CKEDITOR.replace('desTextarea', {
        toolbar: 'Basic'
        //uiColor: '#9AB8F3'//界面颜色
    });
    $("#regionselect").val($('#hidregionId').val());
    LoadDistict($('#hidregionId').val());
    $("#districtselect").val($('#hiddistrictId').val());
    CKEDITOR.instances.desTextarea.setData(HtmlUtil.htmlDecodeByRegExp($('#hidCom').val()));

    $("#regionselect").change(function () {
        var rid = $("#regionselect").val();
        if (rid == "") {
            $("#districtselect").empty();
        } else {
            $.ajax({
                data: { regionid: rid },
                type: "POST",
                url: "/Area/getdistrict",
                datatype: "json",
                success: function (data) {
                    var selectdata = data.date;
                    $("#districtselect").empty();
                    for (var i = 0; i < selectdata.length; i++) {
                        $("#districtselect").append('<option value=' + selectdata[i].DistrictID + '>' + selectdata[i].DistrictName + '</option>');
                    }
                }
            });
        }
    });
    $('#ProupdateForm')
    .bootstrapValidator({
        message: 'This value is not valid',
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            ProvinceName: {
                message: 'The Province Name is not valid',
                validators: {
                    notEmpty: {
                        message: 'The Province Name is required and can\'t be empty'
                    }
                }
            }
        }
    })
    .on('success.form.bv', function (e) {
        e.preventDefault();
        SubData();
    });
});
function LoadDistict(rid) {
    if (rid == "") {
        $("#districtselect").empty();
    } else {
        $.ajax({
            data: { regionid: rid },
            type: "POST",
            url: "/Area/getdistrict",
            datatype: "json",
            success: function (data) {

                var selectdata = data.date;
                $("#districtselect").empty();
                for (var i = 0; i < selectdata.length ; i++) {
                    $("#districtselect").append('<option value=' + selectdata[i].DistrictID + '>' + selectdata[i].DistrictName + '</option>');
                }
            }
        });
    }

}